package com.bugpool.leilema.tc.mapper;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bugpool.leilema.freamwork.annotation.DataScope;
import com.bugpool.leilema.tc.bean.entity.SysUser;
import com.bugpool.leilema.tc.bean.entity.SysUserRole;
import com.bugpool.leilema.tc.bean.enums.StatusEnum;
import com.bugpool.leilema.tc.bean.req.LoginReq;
import com.bugpool.leilema.tc.bean.req.UserReq;
import com.bugpool.leilema.tc.bean.res.UserRes;
import org.apache.catalina.webresources.WarResource;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author wh
 * @Description
 * @Date 2023/3/1 14:54
 * @Version 1.0
 **/
@Mapper
public interface UserMapper extends BaseMapper<SysUser> {
    /**
     * 登录
     *
     * @param loginReq
     * @return
     */
    default SysUser login(LoginReq loginReq) {
        QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(SysUser::getUserName, loginReq.getUserName())
                .eq(SysUser::getPassword, loginReq.getPassword())
        ;
        return this.selectOne(wrapper);
    }
    /**
     * @param page
     * @param userReq
     * @return
     */
    @DataScope("us")
    Page<UserRes> pageList(Page<UserRes> page, @Param("userReq") UserReq userReq);


    /**
     * 更新用户状态
     *
     * @param userId
     * @param status
     */
    default void updateStatus(Long userId, String status) {
        UpdateWrapper<SysUser> wrapper = new UpdateWrapper<>();
        wrapper.lambda().set(SysUser::getStatus, status).eq(SysUser::getUserId, userId);
        this.update(new SysUser(), wrapper);
    }

    /**
     * 根据用户id 获取详情
     *
     * @param userId
     * @return
     */
    UserRes getUserInfo(@Param("userId") Long userId);
}
